package com.dt.platform.generator.module.hr;


import com.dt.platform.constants.db.HrTables;
import com.dt.platform.constants.enums.common.StatusEnableEnum;
import com.dt.platform.constants.enums.common.YesNoEnum;
import com.dt.platform.constants.enums.hr.ReleaseStatusEnum;
import com.dt.platform.domain.hr.Learn;
import com.dt.platform.domain.hr.meta.LearnReleaseMeta;
import com.dt.platform.generator.config.Config;
import com.dt.platform.hr.page.LearnReleasePageController;
import com.dt.platform.proxy.hr.LearnReleaseServiceProxy;
import com.github.foxnic.generator.builder.view.config.DatePickerType;
import com.github.foxnic.generator.config.WriteMode;
import org.github.foxnic.web.domain.hrm.Employee;
import org.github.foxnic.web.domain.hrm.Organization;


public class ALearnReleaseGtr extends BaseCodeGenerator {
    public ALearnReleaseGtr() {
        super(HrTables.HR_LEARN_RELEASE.$TABLE,"811268060357853184");
    }

    public void generateCode() throws Exception {
        System.out.println(this.getClass().getName());

        cfg.view().field(HrTables.HR_LEARN_RELEASE.ID).basic().hidden(true);

        cfg.view().field(HrTables.HR_LEARN_RELEASE.RCD_TIME).form().dateInput().type(DatePickerType.datetime).format("yyyy-MM-dd HH:mm:ss").search().range();
        cfg.view().field(HrTables.HR_LEARN_RELEASE.CREATE_TIME).search().range();

        cfg.view().field(HrTables.HR_LEARN_RELEASE.CODE).search().fuzzySearch();


        cfg.getPoClassFile().addListProperty(Organization.class,"selectOrg","所属公司","所属公司");
        cfg.getPoClassFile().addListProperty(String.class,"selectOrgIds","使用公司/部门","使用公司/部门");

        cfg.getPoClassFile().addListProperty(Employee.class,"selectUser","选择人员","选择人员");
        cfg.getPoClassFile().addListProperty(String.class,"selectUserIds","选择人员","选择人员");

        cfg.getPoClassFile().addSimpleProperty(Learn.class,"learn","learn","learn");
        cfg.view().search().rowsDisplay(1);
        cfg.view().search().inputLayout(
                new Object[]{
                        HrTables.HR_LEARN_RELEASE.STATUS,
                        HrTables.HR_LEARN_RELEASE.RELEASE_STATUS,
                        HrTables.HR_PAPER_RELEASE.CODE,
                        HrTables.HR_LEARN_RELEASE.CREATE_TIME,
                }
        );

        cfg.view().list().disableBatchDelete();

        cfg.view().field(HrTables.HR_LEARN_RELEASE.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_RELEASE.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_RELEASE.UPDATE_TIME).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_RELEASE.CREATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_RELEASE.LEARN_ID).form().table().disable(true);

        cfg.view().field(HrTables.HR_LEARN_RELEASE.SEL_ORG).form().table().disable(true);
        cfg.view().field(LearnReleaseMeta.SELECT_ORG_IDS).form().table().disable(true);
        cfg.view().field(LearnReleaseMeta.SELECT_USER_IDS).form().table().disable(true);

        cfg.view().search().labelWidth(1,Config.searchLabelWidth);
        cfg.view().search().labelWidth(2,Config.searchLabelWidth);
        cfg.view().search().labelWidth(3,Config.searchLabelWidth);
        cfg.view().search().labelWidth(4,Config.searchLabelWidth);
        cfg.view().search().inputWidth(Config.searchInputWidth);

        cfg.view().field(HrTables.HR_LEARN_RELEASE.COST).form().validate().required().form().numberInput().decimal().scale(1).defaultValue(30.0);

        cfg.view().field(HrTables.HR_LEARN_RELEASE.STATUS).form().validate().required().form()
                .radioBox().enumType(StatusEnableEnum.class).defaultIndex(0);

        cfg.view().field(HrTables.HR_LEARN_RELEASE.RELEASE_STATUS).form().validate().required().form()
                .radioBox().enumType(ReleaseStatusEnum.class).defaultIndex(0);


        cfg.view().field(HrTables.HR_LEARN_RELEASE.IF_ALL_USER).form().validate().required().form()
                .radioBox().enumType(YesNoEnum.class).defaultIndex(1);

        cfg.view().search().rowsDisplay(1);
        cfg.view().formWindow().width("80%");;
        cfg.view().formWindow().bottomSpace(150);

        cfg.view().list().addToolButton("生成任务","release","release");

        cfg.view().list().operationColumn().addActionButton("作废","cancelRelease","cancelRelease");

        cfg.view().list().operationColumn().addActionButton("下发任务","releaseAgain","releaseAgain");
        cfg.view().list().operationColumn().addActionButton("任务查询","taskQuery","taskQuery");
        cfg.view().list().addJsVariable("LEARN_ID","[[${learnId}]]","learnId");
        cfg.view().form().addJsVariable("LEARN_ID","[[${learnId}]]","learnId");

        cfg.view().field(LearnReleaseMeta.SELECT_USER_IDS).basic().label("选择人员").form().button().chooseEmployee(false);
        cfg.view().field(LearnReleaseMeta.SELECT_ORG_IDS).basic().label("选择部门").form().button().chooseOrganization(false);

        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_LEARN_RELEASE.STATUS,
                        HrTables.HR_LEARN_RELEASE.COST,
                },
                new Object[] {
                        HrTables.HR_LEARN_RELEASE.SDATE,
                        HrTables.HR_LEARN_RELEASE.EDATE,
                }
        );

        cfg.view().form().addGroup("下发范围",
                new Object[] {
                        HrTables.HR_LEARN_RELEASE.IF_ALL_USER,
                }
        );

        cfg.view().form().addGroup(null,
                new Object[] {
                        LearnReleaseMeta.SELECT_USER_IDS
                }
        );




        //文件生成覆盖模式
        cfg.overrides()
                .setServiceIntfAnfImpl(WriteMode.IGNORE) //服务与接口
                .setControllerAndAgent(WriteMode.IGNORE) //Rest
                .setPageController(WriteMode.IGNORE) //IGNORE
                .setBpmEventAdaptor(WriteMode.COVER_EXISTS_FILE)
                .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
                .setListPage(WriteMode.COVER_EXISTS_FILE) //列表HTML页
                .setExtendJsFile(WriteMode.IGNORE);
        //生成代码
        cfg.buildAll();
    }

    public static void main(String[] args) throws Exception {
        ALearnReleaseGtr g=new ALearnReleaseGtr();
        //生成代码
        g.generateCode();

        //移除之前生成的菜单，视情况执行
       // System.out.println("############"+g.getTablePrefix());
       // g.removeByBatchId("801716675761143808");
      //  //生成菜单
      // g.generateMenu(LearnReleaseServiceProxy.class, LearnReleasePageController.class);
    }
}
